<?php

App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class ProductDetailController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
	public $uses = array('Product', 'Category');

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 * @throws NotFoundException When the view file could not be found
 *	or MissingViewException in debug mode.
 */
	public function index() {
		
		$this->set('title_for_layout', 'Chi tiết');
		
		$product_id = $_GET['productId'];
		
		$this->Product->updateView($product_id);
		
		$detail = $this->Product->getProductDetail($product_id);
		$this->set('detail', $detail);
		
		$categoryName = $this->Category->find('first', array('conditions' => array('id' => $detail['Product']['category_id'])));
		$this->set('categoryName', $categoryName);
		
		$sameList = $this->Product->find('all', array('limit' => 4, 'conditions' => array('id <>' => $product_id, 'category_id' => $detail['Product']['category_id'])));
		$this->set('sameList', $sameList);
	}
}
